package com.lujianfei.waterpower.ui.preview;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;

import com.github.chrisbanes.photoview.OnViewTapListener;
import com.github.chrisbanes.photoview.PhotoView;
import com.lujianfei.share.ShareHelper;
import com.lujianfei.share.shareBase.SharePlatforms;
import com.lujianfei.waterpower.R;
import com.lujianfei.waterpower.base.BaseActivity;
import com.lujianfei.waterpower.utils.CameraAlbum.FileProviderUtils;
import com.lujianfei.waterpower.utils.ResUtils;
import com.lujianfei.waterpower.utils.StatusBarUtils;

public class PreviewActivity extends BaseActivity {

    public static final String KEY_URI = "keyuri";

    PhotoView photoView;
    String keyUri;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        StatusBarUtils.with(this).setColor(ResUtils.getColor(R.color.black)).init();
        setContentView(R.layout.activity_preview);
        setTitleBackgroundColor(ResUtils.getColor(R.color.transparent));
        setTitleRightImage(R.drawable.ic_share);
        showTitleRightImage();
        keyUri = getIntent().getStringExtra(KEY_URI);
        photoView = findViewById(R.id.photoView);
        try {
            Bitmap bitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(Uri.parse(keyUri)));
            photoView.setImageBitmap(bitmap);
        } catch (Exception e) {
            e.printStackTrace();
        }
        photoView.setOnViewTapListener(new OnViewTapListener() {
            @Override
            public void onViewTap(View view, float x, float y) {
                finish();
            }
        });
    }

    @Override
    public void onTitleRightImageClick() {
        super.onTitleRightImageClick();
        String imagePath = FileProviderUtils.getPathFromUri(this,Uri.parse(keyUri));
        new ShareHelper(this)
                .share("图片分享", "分享内容", "图片分享")
                .image(new String[]{imagePath}) //图片路径
                .withPlatforms(
                        SharePlatforms.ShareTypeQQ,
                        SharePlatforms.ShareTypeWechat)
                .show();
    }

    @Override
    protected int getTitleBarResId() {
        return R.id.custom_titlebar;
    }
}
